package com.ruoyi.web.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nongjt.domain.PrinterAuth;
import com.ruoyi.nongjt.service.IPrinterAuthService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * 打印机认证Controller(前端Web)
 * 
 * @author ruoyi
 * @date 2024-09-27
 */
@RestController
@RequestMapping("/web/printerAuth")
public class WebPrinterAuthController extends BaseController
{
    @Autowired
    private IPrinterAuthService printerAuthService;

    /**
     * 查询打印机认证列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrinterAuth printerAuth)
    {
        startPage();
        List<PrinterAuth> list = printerAuthService.selectPrinterAuthList(printerAuth);
        return getDataTable(list);
    }

    /**
     * 导出打印机认证列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:export')")
    @Log(title = "打印机认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrinterAuth printerAuth)
    {
        List<PrinterAuth> list = printerAuthService.selectPrinterAuthList(printerAuth);
        ExcelUtil<PrinterAuth> util = new ExcelUtil<PrinterAuth>(PrinterAuth.class);
        util.exportExcel(response, list, "打印机认证数据");
    }

    /**
     * 获取打印机认证详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:query')")
    @GetMapping(value = "/{authId}")
    public AjaxResult getInfo(@PathVariable("authId") Long authId)
    {
        return success(printerAuthService.selectPrinterAuthByAuthId(authId));
    }

    /**
     * 新增打印机认证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:add')")
    @Log(title = "打印机认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrinterAuth printerAuth)
    {
        return toAjax(printerAuthService.insertPrinterAuth(printerAuth));
    }

    /**
     * 修改打印机认证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:edit')")
    @Log(title = "打印机认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrinterAuth printerAuth)
    {
        return toAjax(printerAuthService.updatePrinterAuth(printerAuth));
    }

    /**
     * 删除打印机认证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:printerAuth:remove')")
    @Log(title = "打印机认证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{authIds}")
    public AjaxResult remove(@PathVariable Long[] authIds)
    {
        return toAjax(printerAuthService.deletePrinterAuthByAuthIds(authIds));
    }
}